# 重写jwt返回结果的方法，按照接口文档返回数据内容
def jwt_response_payload_handler(token, user=None, request=None):
    """
    :param token: 生成好的token
    :param user: 用户对象
    :param request: 请求对象
    :return:
    """
    return {
        'token': token,
        'id': user.id,
        'username': user.username
    }


# 自定义分页器
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from collections import OrderedDict


class NumPage(PageNumberPagination):
    # 指定最大页容量
    max_page_size = 5
    # 指定页容量参数
    page_size_query_param = 'pagesize'

    # 重写返回结果
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('lists', data),
            ('page', self.page.number),
            ('pages', self.page.paginator.num_pages),
            ('pagesize', 10),
        ]))
